package com.wgc.vip.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wgc.entity.PageResult;
import com.wgc.entity.Result;
import com.wgc.vip.domain. PointsHistory;
import com.wgc.vip.service.PointsHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 会员积分
 */
@RestController
@RequestMapping("/pointsHistory")
public class PointsHistoryController {
    @Autowired
    private PointsHistoryService pointsHistoryService;
    /**
     *查看全部
     *  */
    @RequestMapping("/getAll")
    public Result<List< PointsHistory>> getAll(){
        return new Result("查询成功",pointsHistoryService.getAll());
    }
    /**
     *新增
     *  */
    @RequestMapping("/insert")
    public Result insert( PointsHistory e){
        return new Result("新增成功",pointsHistoryService.insert(e));
    }
    /**
     *删除
     *  */
    @RequestMapping("/delete")
    public Result delete(@RequestParam String ids){
        return new Result("删除成功",pointsHistoryService.delete(ids));
    }

    /**
     * 分页搜索实现
     */
    @GetMapping(value = "/pageList" )
    public Result pageList(@RequestParam(defaultValue = "1")  Integer page, @RequestParam(defaultValue = "10") Integer size) {
        Page< PointsHistory> ePage = pointsHistoryService.pageAll(page, size);
        PageResult< PointsHistory> pageResult = new PageResult<>(ePage.getTotal(), ePage.getRecords());
        return new Result<>("查询成功", pageResult);
    }
    /**
     * 分页条件搜索
     */
    @GetMapping(value = "/pageList" )
    public Result pageList(@RequestBody  PointsHistory e, @RequestParam(defaultValue = "1")  Integer page, @RequestParam(defaultValue = "10") Integer size) {
        Page< PointsHistory> ePage = pointsHistoryService.pageList(e, page, size);
        PageResult< PointsHistory> pageResult = new PageResult<>(ePage.getTotal(), ePage.getRecords());
        return new Result<>("查询成功", pageResult);
    }
    /**
     * 根据会员名条件查询
     */
    @GetMapping("/getByName")
    public Result<List< PointsHistory>> getByName(@RequestParam String name){
        return new Result("查询成功",pointsHistoryService.getByName(name));
    }
}
